/*
 * Copyright 2003-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.edu.tsinghua.cic.ccss.task;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.forten.utils.common.NumberUtil;
import org.forten.utils.system.LogUtil;
import org.springframework.stereotype.Component;

import cn.edu.tsinghua.cic.ccss.bo.CadreBo;

/**
 * 
 * 
 * @author <a href="mailto:du_yi@bbn.cn">Duyi</a>
 * @since 2012-5-23
 */
@Component("initCreditEveryMonthTask")
public class InitCreditEveryMonthTask {
	private static Logger log = Logger
			.getLogger(InitCreditEveryMonthTask.class);

	@Resource(name = "cadreBo")
	private CadreBo cadreBo;
	@Resource
	private EhcacheUtil ehcacheUtil;

	public void initCredit() {
		try {
			Thread.sleep(NumberUtil.getRandomInteger(1, 2000));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		LogUtil.info(log, "creditFlag is : %d",
				ehcacheUtil.getFlag("creditFlag"));
		if (ehcacheUtil.getFlag("creditFlag") != 0) {
			// ehcacheUtil.setFlag("creditFlag", 0);
			return;
		} else {
			ehcacheUtil.setFlag("creditFlag", 1);
			cadreBo.initCredit();
		}
	}
}
